﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prob_Distributions_ClassLibrary
{
    class DistribucionPoisson : IDistribucion
    {
        private RandomNumber rnd;
        private double lambda;
        private double menor;
        private double mayor;

        public DistribucionPoisson(RandomNumber rnd, double media)
        {
            this.rnd = rnd;
            this.lambda = (double)(1/media);
        }
        public List<double> getNRandoms(int cant)
        {
            List<double> lstNros = new List<double>();

            for (int i = 0; i < cant; i++)
            {
                int nro = getPoisson(lambda);
                if (i == 0)
                {
                    menor = double.MaxValue;
                    mayor = 0;
                }
                lstNros.Add(nro);
                if (lstNros[i] > mayor)
                    mayor = lstNros[i];
                if (lstNros[i] < menor)
                    menor = lstNros[i];
                
            }
            return lstNros;
        }

        public int getPoisson(double lambda)
        {
            double p = 1;
            int x = -1;
            double a = Math.Exp(-lambda);
            

            do
            {
                double u = rnd.NextRandom();
                p = p * u;
                x++;
            } while (p >= a);

            return x;
        }
        public decimal getMayor()
        {
            return (decimal) mayor;
        }
        public decimal getMenor()
        {
            return (decimal)menor;
        }
        public decimal getIntervalo(int intervalos)
        {
            return (decimal)(mayor - menor) / intervalos;
        }
        public double getLimiteSuperior()
        {
            return mayor;
        }
        public double getLimiteInferior()
        {
            return menor;
        }
    }
}
